﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _9.MostFrequentNumberInArray
{
    class MostFrequentNumberInArray
    {
        static void Main(string[] args)
        {
            int[] numbers = { 1, 6, 1, 6, 1, 1, 7, 8, 9, 2, 1, 2, 4, 4, 5, 6, 6, 6, 6, 6 };
            int checknumber = 0;
            int counter = 0;
            int bestseq = Int16.MinValue;
            int number = 0;
            for (int i = 0; i < numbers.Length; i++)
            {
                checknumber = numbers[i];
                for (int j = 1; j < numbers.Length; j++)
                {
                    if (checknumber == numbers[j])
                    {
                        counter++;
                    }
                    if (counter > bestseq)
                    {
                        bestseq = counter;
                        number = numbers[j];
                    }
                }
                counter = 0;
            }
            Console.WriteLine("Most frequent number is: {0} -> {1} times",number,bestseq);
        }
    }
}
